package com.cn.studey.utils;

import com.cn.studey.annotations.UserLog;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Map;

/**
 * @author mjy
 * @date 2021/05/14
 * @description
 */
public class ApartLogUtils {

    public static void modifyAnnotation(Method method, String operationContent) {

        UserLog auditLog = method.getAnnotation(UserLog.class);
        InvocationHandler invocationHandler = Proxy.getInvocationHandler(auditLog);
        Field value = null;
        try {
            value = invocationHandler.getClass().getDeclaredField("memberValues");
            value.setAccessible(true);
            Map<String, Object> memberValues = (Map<String, Object>) value.get(invocationHandler);
            //获取该注解的值
            String val = (String) memberValues.get("describe");
            //覆盖这个value（操作类型）
            memberValues.put("describe", operationContent);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

    }

}
